package com.evl.trainOrder.controller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.evl.api.trainOrder.vo.TrainOrderSearchRQ;
import com.evl.common.controller.BaseController;
import com.evl.common.persistence.dao.TrainOrderMapper;
import com.evl.common.persistence.model.TrainOrder;
import com.evl.trainOrder.service.ITrainOrderService;

/**
 * 用户订单控制器
 *
 * @author
 * @Date 2017-06-20 20:22:23
 */
@Controller
@RequestMapping("/trainOrder")
public class TrainOrderController extends BaseController {

	private static Logger log = LoggerFactory.getLogger(BaseController.class);

	private String PREFIX = "/trainOrder/";


	@Resource
	ITrainOrderService orderService;
	
	@Resource
	TrainOrderMapper trainOrderMapper;

	/**
	 * 跳转到用户订单首页
	 */
	@RequestMapping("")
	public String index() {
		return PREFIX + "trainOrder.html";
	}

	/**
	 * 跳转到添加用户订单
	 */
	@RequestMapping("/trainOrder_add")
	public String trainOrderAdd() {
		return PREFIX + "trainOrder_add.html";
	}

	/**
	 * 跳转到修改用户订单
	 */
	@RequestMapping("/trainOrder_update/{trainOrderId}")
	public String trainOrderUpdate(@PathVariable Integer trainOrderId,
			Model model) {
		Object rs = detail(trainOrderId);
		model.addAttribute("trainOrderDetail", rs);
		return PREFIX + "trainOrder_edit.html";
	}

	
	/**
	 * 获取用户订单列表
	 */
	@RequestMapping(value = "/list")
	@ResponseBody
	public Object list(TrainOrder trainOrder) {
		return orderService.selectTrainOrders(trainOrder);
	}

	/**
	 * 新增用户订单
	 */
	@RequestMapping(value = "/add")
	@ResponseBody
	public Object add(TrainOrder trainOrder) {
		return null;
	}

	/**
	 * 删除用户订单
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	public Object delete(@RequestParam Integer trainOrderId) {
		return null;
	}

	/**
	 * 修改用户订单
	 */
	@RequestMapping(value = "/update")
	@ResponseBody
	public Object update(TrainOrder trainOrder) {

		return null;
	}

	/**
	 * 用户订单详情
	 */
	@RequestMapping(value = "/detail")
	@ResponseBody
	public Object detail(@RequestParam Integer trainOrderId) {
		TrainOrderSearchRQ rq = new TrainOrderSearchRQ();
		rq.setId(trainOrderId+"");
		return trainOrderMapper.findTrainOrders(rq).get(0);
	}
}

